package cn.stylefeng.guns.modular.gridsystem.utils;

import cn.hutool.http.HttpUtil;
import cn.stylefeng.guns.core.context.constant.ConstantContextHolder;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 声纹引擎工具类
 *
 * @author ssy
 * @date 2021/11/10 9:30
 */
public class CollectorConfigUtil {

    private final static Integer serverPort = 8888;

    //***************************8路采集器*****************************************//

    /**
     * 修改8路采集板采集时间
     *
     * @param time
     * @return
     */
    public static String recordingTime(String collectoeIp, Integer time) {
        Map<String, Object> map = new HashMap<>();
        map.put("time", time);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/serial/change/board/recordingTime", map, 5000);
    }

    /**
     * 停止录音
     *
     * @return
     */
    public static String stopRecording(String collectoeIp) {
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/serial/change/board/stopRecording", 5000);
    }

    /**
     * 修改盒子IP
     */
    public static String boxIP(String collectoeIp, String ip, Integer time) {
        Map<String, Object> map = new HashMap<>();
        map.put("ip", ip);
        map.put("time", time);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/serial/change/board/boxIP", map, 5000);
    }

    /**
     * 修改FTP服务器IP
     */
    public static String serverIP(String collectoeIp, String ip, Integer port, Integer time) {
        Map<String, Object> map = new HashMap<>();
        map.put("ip", ip);
        map.put("port", port);
        map.put("time", time);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/serial/change/board/serverIP", map, 5000);
    }

    /**
     * 修改采样率或音量
     */
    public static String rateOrVolume(String collectoeIp, Integer volume, String channel, String samplingRate, Integer time) {
        Map<String, Object> map = new HashMap<>();
        map.put("volume", volume);
        map.put("channel", channel);
        map.put("samplingRate", samplingRate);
        map.put("time", time);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort  + "/api/serial/change/board/rateOrVolume", map, 5000);
    }

    /**
     * 更改8路采集板服务器的用户名或密码
     *
     * @param userNameOrPassWord
     * @param changeType         类型(0:修改用户名  1:修改密码)
     * @return
     */
    public static String userNameOrPassWord(String collectoeIp, String userNameOrPassWord, Integer changeType) {
        Map<String, Object> map = new HashMap<>();
        map.put("userNameOrPassWord", userNameOrPassWord);
        map.put("changeType", changeType);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/serial/change/board/userNameOrPassWord", map, 5000);
    }

    //***************************主动发声采集器*****************************************//

    /**
     *
     * @param collectoeIp
     * @param frequency
     * @param volumeActiveVoice
     * @param workingTime
     * @param intermittentTime
     * @return
     */
    public static String parameter(String collectoeIp, Integer frequency, Integer volumeActiveVoice,Integer workingTime,Integer intermittentTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("frequency", frequency);
        map.put("volumeActiveVoice", volumeActiveVoice);
        map.put("workingTime", workingTime);
        map.put("intermittentTime", intermittentTime);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/soundMaker/change/parameter", map, 5000);
    }

    public static String startOrStop(String collectoeIp,String startOrStop){
        Map<String, Object> map = new HashMap<>();
        map.put("startOrStop", startOrStop);
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/soundMaker/startOrStop", map, 5000);
    }

    //***************************自检*****************************************//
    /**
     * 自检测试
     */
    public static String selfTest(String collectoeIp){
        return HttpUtil.get("http://"+collectoeIp+":"+serverPort + "/api/line/test", 5000);
    }

    /**
     * 注册模型
     */
    public static String register(String collectoeIp, String accessToken, String groupId, File[] files){
        Map<String, Object> map = new HashMap<>();
        map.put("accessToken", accessToken);
        map.put("groupId", groupId);
        map.put("files", files);
        return HttpUtil.post(collectoeIp + "/api/post/register",map, 5000);
    }

}
